package com.sskj.mine.ui.activity;


import android.widget.CheckBox;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.FbShop;
import com.sskj.mine.component.DaggerUserDataComponent;
import com.sskj.mine.presenter.ApplyShopActivityPresenter;

import javax.inject.Inject;

import butterknife.BindView;

@Route(path = RConfig.MINE_APPLY_SHOP)//申请商家
public class ApplyShopActivity extends BaseActivity<ApplyShopActivityPresenter> {
    @Inject
    UserViewModel userViewModel;
    @BindView(R2.id.tvContent)
    TextView tvContent;
    @BindView(R2.id.apply_checkbox)
    CheckBox applyCheckbox;
    @BindView(R2.id.tvFreeze)
    TextView tvFreeze;
    @BindView(R2.id.btApplySeller)
    TextView btApplySeller;
    private UserData userData;

    @Override
    protected int getLayoutResId() {
        return R.layout.mine_activity_apply_shop;
    }

    @Override
    public ApplyShopActivityPresenter getPresenter() {
        return new ApplyShopActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(getString(R.string.mine_shop_apply));
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
            }
        });
        ClickUtil.click(btApplySeller, () -> {
            if (applyCheckbox.isChecked()) {
                mPresenter.apply();
            } else {
                ToastUtil.showShort(R.string.mine_apply_shop1);
            }
        });
    }

    @Override
    protected void initData() {
        mPresenter.fbShopNumber();
    }

    public void applySuccess() {
        userViewModel.update();
        finish();
    }

    public void updateUser(FbShop data) {
        tvContent.setText(String.format(getString(R.string.mine_apply_shop2), data.getValue()));
        tvFreeze.setText(String.format(getString(R.string.mine_apply_shop3), data.getValue()));     // 单选框 文本
    }

    @Override
    public boolean getImmersion() {
        return false;
    }
}
